Traditionally, computer programs are written in a computer programming language such that the programs are specific to a particular type of computer. For example, a program written in the computer programming language C++ for the Microsoft.TM. WindowS.TM. operating system is usually not able to also run on a computer in which the Apple.TM. MacOS.TM. operating system is installed. This means that computer programmers must write different versions of their programs for each different type of computer on which the programs are desired to be run.
With the advent of more universal programming languages such as Java, however, programs may be written such that ideally they can be run on any type of computer. For example, a program written in Java ideally is able to run on a computer on which the Microsoft.TM. Windows.TM. operating system is installed, as well as on a computer on which the Apple.TM. MacOS.TM. operating system is installed. The computer programmer is not forced to rewrite the program for each different type of computer on which the program is desired to be run.
One manner by which programming languages such as Java provide for this write-once-run-anywhere capability is to have a two-step compilation process. A computer program is written in source code by a computer programmer, and is first compiled from source code to an intermediate code, which is known as byte code in the case of Java. When the program is run on a specific computer, a just-in-time compiler then compiles the byte code to machine code that the specific computer understands.
Furthermore, this machine code is executed on the specific computer in conjunction with a run-time system known as a virtual machine, which acts as an intermediary between the computer program and the operating system installed on the specific computer. However, the just-in-time compiler, in compiling the byte code to machine code, may need to ensure that various conditions and operations of the code (i.e., such as which registers are being used by the code, and which are unused) are being properly reported to the virtual machine. That is, the just-in-time compiler typically needs to interact with the virtual machine on the specific computer.
Typically, this is accomplished by inserting a function call within the machine code to the virtual machine for execution when the computer program is run. For example, what are known in the art as garbage collection routines (i.e., specialized memory management routines) are usually implemented at the virtual machine, such that during execution the machine code may have to at times call a garbage collection routine to provide information the routine needs in the form of what is known in the art as a write barrier instruction. Frequently, however, this run-time function call within the machine code becomes a bottleneck, slowing down the execution of the computer program.
A limited solution to this problem is to have the just-in-time compiler be aware of the specific routines within a virtual machine, such that the compiler can itself insert code for the routines when compiling byte code to machine code, thus eliminating the need for inserting a run-time function call to the virtual machine. However, a disadvantage to this solution is that it is counter to the philosophy of write-once-run-anywhere capability. If the specific routines change, without a corresponding change to the code inserted by the compiler, then the resulting machine code into which the incorrect code is inserted may not operate when the program is executed. That is, this limited solution trades flexibility for speed of execution. These and other disadvantages are addressed by the present invention.